package csci6450.chickenFriedFS.nuggetCore;

import java.io.Serializable;
import java.util.Date;


/**
 *  <p style="margin-top: 0">
 *      Models a 64MB chunk of data that contains all or part of a logical file.
 *  </p>
 */
// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.8AC91BC0-56E6-0AE0-8282-53C2795C2ED1]
// </editor-fold> 
public class Nugget implements Serializable{

    private Date timestamp;

    private byte[] nugget;

    private String parentFilename;

    private String nuggetLocation;

    private int nuggetPosition;

    private String nuggetIdentifier;

    private int parentFileNuggetCount;

    private long nuggetOffset;

    private long repNuggetOffset;

    private int nuggetServerPort;

    private int bufferStart;

    private String nuggetRepLocation;

    private int nuggetRepPort=-1;


    public Nugget (byte[] nugget) {
        this.nugget = nugget;
        this.timestamp = new Date();
    }
    public Nugget (byte[] nugget, String fileName) {
        this.nugget = nugget;
        this.parentFilename = fileName;
        this.timestamp = new Date();
    }

    public Nugget(String parentFileName, int nuggetPosition,
            int parentFileNuggetCount, String nuggetIdentifier,
            String nuggetLocation, byte[] nugget, int port){
        this.parentFilename = parentFileName;
        this.nuggetPosition = nuggetPosition;
        this.parentFileNuggetCount = parentFileNuggetCount;
        this.nuggetIdentifier = nuggetIdentifier;
        this.nuggetLocation = nuggetLocation;
        this.nugget = nugget;
        this.timestamp = new Date();
        this.nuggetServerPort = port;
    }


    public Nugget(String parentFileName, int nuggetPosition,
            int parentFileNuggetCount, String nuggetIdentifier,
            String nuggetLocation, int port){
        this.parentFilename = parentFileName;
        this.nuggetPosition = nuggetPosition;
        this.parentFileNuggetCount = parentFileNuggetCount;
        this.nuggetIdentifier = nuggetIdentifier;
        this.nuggetLocation = nuggetLocation;
        this.timestamp = new Date();
        this.nuggetServerPort = port;
    }

    public Nugget(String parentFileName, int nuggetPosition,
            int parentFileNuggetCount,String nuggetIdentifier,
            String nuggetLocation, long nuggetOffset, Date timestamp, int port, int bufferStart){
        this.parentFilename = parentFileName;
        this.nuggetPosition = nuggetPosition;
        this.parentFileNuggetCount = parentFileNuggetCount;
        this.nuggetIdentifier = nuggetIdentifier;
        this.nuggetLocation = nuggetLocation;
        this.nuggetOffset = nuggetOffset;
        this.timestamp = timestamp;
        this.nuggetServerPort = port;
        this.bufferStart = bufferStart;
    }

    public byte[] getNugget () {
        return nugget;
    }

    public void setNugget (byte[] val) {
        this.nugget = val;
    }

    public String getNuggetIdentifier () {
        return nuggetIdentifier;
    }

    public void setNuggetIdentifier (String val) {
        this.nuggetIdentifier = val;
    }

    public String getNuggetLocation () {
        return nuggetLocation;
    }

    public void setNuggetLocation (String val) {
        this.nuggetLocation = val;
    }

    public int getNuggetPosition () {
        return nuggetPosition;
    }

    public void setNuggetPosition (int val) {
        this.nuggetPosition = val;
    }

    public int getParentFileNuggetCount () {
        return parentFileNuggetCount;
    }

    public void setParentFileNuggetCount (int val) {
        this.parentFileNuggetCount = val;
    }

    public String getParentFilename () {
        return parentFilename;
    }

    public void setParentFilename (String val) {
        this.parentFilename = val;
    }

    public Date getTimestamp () {
        return timestamp;
    }

    public void setTimestamp (Date val) {
        this.timestamp = val;
    }

    public long getNuggetOffset(){
        return this.nuggetOffset;
    }

    public void setNuggetOffset(long set){
        this.nuggetOffset = set;
    }

    public long getRepNuggetOffset(){
        return this.repNuggetOffset;
    }

    public void setRepNuggetOffset(long set){
        this.repNuggetOffset = set;
    }

    public boolean equals(Nugget nugget){
        return this.parentFilename.equals(nugget.getParentFilename())
                && this.nuggetPosition == nugget.getNuggetPosition();
    }

    public int getNuggetServerPort(){
        return this.nuggetServerPort;
    }

    public void setNuggetServerPort(int set){
        this.nuggetServerPort = set;
    }


    public int getBufferStart(){
        return this.bufferStart;
    }

    public void setBufferStart(int set){
        this.bufferStart = set;
    }

    public String getNuggetRepLocation(){
        return this.nuggetRepLocation;
    }

    public void setNuggetRepLocation(String set){
        this.nuggetRepLocation = set;
    }

    public int getNuggetRepPort(){
        return this.nuggetRepPort;
    }

    public void setNuggetRepPort(int set){
        this.nuggetRepPort = set;
    }

}

